var login = document.getElementById('login')
var log = document.getElementById('log')
var logP = document.getElementById('logP')
var sig = document.getElementById('sig')
console.log(login)
login.addEventListener('click', function() {
	logP.classList.remove("hidden");
	logP.classList.add("show");
	log.classList.remove('hidden');
	log.classList.add('show');
	// 页面载入动画
	const loginCard = document.querySelector('.login-card');
	setTimeout(() => {
		loginCard.classList.add('loaded');
	}, 100);

	// 密码显示/隐藏切换
	const togglePassword = document.getElementById('togglePassword');
	const passwordInput = document.getElementById('password');

	togglePassword.addEventListener('click', function() {
		const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
		passwordInput.setAttribute('type', type);

		// 切换眼睛图标
		togglePassword.textContent = type === 'password' ? '👁️' : '🔒';
	});

	// 用户名输入监听
	const loginIdInput = document.getElementById('loginId');
	const avatarContainer = document.getElementById('avatarContainer');
	const userAvatar = document.getElementById('userAvatar');

	loginIdInput.addEventListener('input', function() {
		const username = this.value.trim().toLowerCase();

		if (username.length < 3) {
			avatarContainer.classList.remove('avatar-loaded');
			return;
		}

	});
	// 表单提交处理
	
});

const responseMessage = document.getElementById('responseMessage');
const loginBtn = document.getElementById('loginBtn');
const loginBtnText = document.getElementById('loginBtnText');
loginBtn.addEventListener('click', function(e) {
	e.preventDefault()
	let username = $('#loginId').val();
	let password = $('#password').val();
	console.log(username)
	console.log(password)
	$.ajax({
		url: "loginDo",
		type: 'get',
		data: {
			username:username,
			password:password
		},
		success: function(data) {
			$('#loginInfo').text(data)
			console.log(data)
			if(data == '' || data == null){
				location.reload(true);
			}
		},
		error: function(xhr, status, error) {
			console.log('Error:', status, error);
		},
		dataType: 'text'
	})
	return false;
})